﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HarveyNash.RefactoringAndCodeSmell.Refactoring.DecomposeConditional
{
    class After
    {
        private readonly double DISCOUNT_PERCENTAGE = 0.05; //5%
        private readonly double VAT = 0.10; //10%
       
        public double CalculateTotalPayment(string code, float quantity, float unitPrice)
        {
            if (IsDiscountedCategory(code))
                return CalculatePaymentWithDiscount(quantity, unitPrice);
            else
                return CalculatePayment(quantity, unitPrice);
        }

        private bool IsDiscountedCategory(string code)
        {
            return code.StartsWith("LCD") || code.StartsWith("KB") || code.StartsWith("HDD") || code.StartsWith("CPU");
        }

        private double CalculatePaymentWithDiscount(float quantity, float unitPrice)
        {
            return quantity * unitPrice * (1 + VAT - DISCOUNT_PERCENTAGE);
        }

        private double CalculatePayment(float quantity, float unitPrice)
        {
            return quantity * unitPrice * (1 + VAT);
        }         
    }
}
